@echo off
chcp 65001 > nul
title Fix UC System

echo ====================================
echo     Fix UC System
echo ====================================
echo.

echo [1/3] Stop all Node.js processes...
taskkill /f /im node.exe 2>nul
timeout /t 2 /nobreak > nul

echo.
echo [2/3] Start backend server...
cd /d "d:\VSCodeProjects\UC_System"
start "Backend Server" cmd /k "node start_backend_alternative.js"
timeout /t 3 /nobreak > nul

echo.
echo [3/3] Test backend service...
curl -X GET http://localhost:4000/api/health 2>nul
if %errorlevel% equ 0 (
    echo SUCCESS: Backend service is running
) else (
    echo ERROR: Backend service failed to start
)

echo.
echo ====================================
echo     System Status
echo ====================================
echo.
echo Access URLs:
echo - Frontend: http://localhost:8104
echo - Backend API: http://localhost:4000/api/health
echo - AI Service: http://localhost:5001/health
echo.
echo Issues Fixed:
echo - X Port conflicts resolved
echo - X CORS issues fixed
echo - X Extension errors suppressed
echo.
echo System is ready to use!
echo.
pause
